<template>
  <div class="main">
    <div class="wrap">
      <div class="search flex flex-wrap flex-align-items-center">
        <div class="search-item flex flex-align-items-center">
          <p class="search-item-label font-14">日期筛选：</p>
          <el-date-picker v-model="form.date" type="daterange" range-separator=" " start-placeholder="开始"
            end-placeholder="结束" />
        </div>
        <div class="search-item flex flex-align-items-center">
          <p class="search-item-label font-14">项目编号：</p>
          <el-input v-model="searchForm.no"></el-input>
        </div>
        <div class="search-item flex flex-align-items-center">
          <p class="search-item-label font-14">项目名称：</p>
          <el-input v-model="searchForm.name"></el-input>
        </div>
        <div class="search-item flex flex-align-items-center">
          <p class="search-item-label font-14">项目状态：</p>
          <el-select v-model="searchForm.status">
            <el-option v-for="item in statusList" :key="item.value" :label="item.name" :value="item.value"></el-option>
          </el-select>
        </div>
        <div class="search-btns flex">
          <p class="font-14 pointer" @click="searchConfirm">查询</p>
          <p class="font-14 pointer" @click="reset">重置</p>
        </div>
      </div>
      <el-table :data="tableData" :height="tableHeight" style="width: 100%;" class="table">
        <el-table-column prop="value" label="创建时间" width="120" />
        <el-table-column prop="value" label="项目编号" width="150" />
        <el-table-column prop="value" label="项目名称" width="150" />
        <el-table-column prop="value" label="项目状态" width="150" />
        <el-table-column prop="value" label="提报次数" width="150" />
        <el-table-column prop="value" label="提报红人" width="150" />
        <el-table-column prop="value" label="执行中" width="150" />
        <el-table-column prop="value" label="上线" />
        <el-table-column label="操作" fixed="right" width="124">
          <template #default="scope">
            <div class="row-btns flex flex-align-items-center">
              <p class="row-btn font-14 pointer" @click="toDetail(scope.row)">详情</p>
              <span class="line"></span>
              <p class="row-btn font-14 pointer" @click="toEdit(scope.row)">编辑</p>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination flex flex-align-items-center">
        <el-pagination layout="prev, pager, next, total" :total="form.total" />
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import api from '@/api/index.js';

const tableHeight = ref(0);
const statusList = ref([
  {
    name: '进行中',
    value: 1
  },
  {
    name: '已完成',
    value: 2
  },
  {
    name: '已取消',
    value: 3
  }
]);
const searchForm = ref({});
const form = ref({
  page: 1,
  perPage: 10,
  total: 1
});
const tableData = ref([]);

const searchConfirm = () => {
  form.value = {
    page: 1,
    perPage: form.value.perPage,
    ...searchForm.value
  }
}
const reset = () => {
  form.value = {
    page: 1,
    perPage: form.value.perPage,
    time: []
  };
  searchForm.value = {};
}

onMounted(() => {
  tableHeight.value = window.innerHeight - 80 - document.getElementsByClassName('table')[0].offsetTop;
});
</script>

<style lang="less" scoped>
.main {
  padding: 16px;
}

.wrap {
  padding: 16px;
  background: #fff;
  border-radius: 2px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .04), 0 2px 8px rgba(0, 0, 0, .04);

  .search {
    margin-bottom: 16px;
    border-bottom: 1px solid #f2f3f5;

    .search-item {
      margin-right: 32px;
      margin-bottom: 16px;

      .search-item-label {
        color: #333;
        width: 80px;
      }

      &::v-deep {
        .el-date-editor {
          width: 282px;
          flex-grow: 0;
        }

        .el-input {
          width: 282px;
        }
      }
    }

    .search-btns {
      margin-bottom: 16px;

      p {
        width: 70px;
        padding: 0 8px;
        height: 32px;
        border-radius: 2px;
        text-align: center;

        &:first-child {
          background: @main-color !important;
          color: #fff;
          margin-right: 24px;
          line-height: 32px;
        }

        &:last-child {
          background: #fff;
          border: 1px solid #d9d9d9;
          color: #333;
          line-height: 30px;
        }
      }
    }
  }

  .pagination {
    justify-content: end;
    margin-top: 16px;
  }
}
</style>
